package com.fanshuai.config;

import org.apache.commons.collections.CollectionUtils;

import java.util.*;

public class EndPoint {
    static List<String> backendServers = new ArrayList<>();

    public static void addServerAddr(String addr) {
        backendServers.add(addr);
    }

    //随机获取server
    public static String getServer() {
        if (CollectionUtils.isEmpty(backendServers)) {
            throw new RuntimeException("backendServers empty");
        }

        Random random = new Random();
        int index = random.nextInt(backendServers.size());
        return backendServers.get(index);
    }

    public static void init() {
        addServerAddr("localhost:8080");
    }
}
